package com.scujj.pojo;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;


@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class Result implements Serializable {


    private Integer code;
    private String message;
    private Object data;

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static Result success() {
        return new Result(0, "成功");
    }

    public static Result success(Object data) {
        return new Result(0, "成功", data);
    }

    public static Result success(String msg) {
        return new Result(0, msg);
    }

    public static Result success(String msg,Object data){
        return new Result(0, msg, data);
    }

    public static Result error() {
        return new Result().setCode(-1);
    }

    public static Result error(String message) {
        return new Result(-1, message);
    }

    public String toJsonString() {
        return JSON.toJSONString(this);
    }
}
